/**
 * @param {string} port
 * @returns {Boolean}
 * 端口号0-65535
 */
export function validPort (port) {
  // if(/(^[1-9]\d*$)|(0)/.test(value) && value >= 0 && value <= 65535) { // 001能通过验证
  // return /(^[0-9]$)|(^[1-9]\d$)|(^[1-9]\d{2}$)|(^[1-9]\d{3}$)|(^[1-6]\d{3}[0-5]$)/.test(port)
  return /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/.test(port)
}

/**
 * @param {string} path
 * @returns {Boolean}
 * 文件路径
 */
export function validPath (path) {
  // return /^[a-zA-Z]:(((\\(?! )[^/:*?<>\""|\\]+)+\\?)|(\\)?)\s*$/.test(path)
  return /^\/(\w+\/?)+$/.test(path)
}

/**
 * @param {string} url
 * @returns {Boolean}
 * url地址
 */
///^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*([\?&]\w+=\w*)*$/.test(value)
export function validURL(url) {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}

/**
 * @param {string} ip
 * @returns {Boolean}
 * ip地址
 */
export function validIP (ip) {
  const reg = /^(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)$/
  return reg.test(ip)
}
